<?php
namespace Home\Controller;
use Think\Controller;
class MoreController extends CommonController {
    public function index(){
		$this->display();
    }
	public function ajax(){  //用来调用josn  加载更多数据效果
		$areas = M('news');
		$last = $_POST['last'];
		$amount = $_POST['amount'];
		$list = $areas->limit($last,$amount)->select();
		foreach($list as $key=>$value){
		$row[] = array(
			'id' => $value['id'],
			'content' => $value['title']
		);
		}
		$this->ajaxReturn($row,JSON);
		$this->display();
	}
	public function ajax_page(){
		$num = 2 ;//要求分页显示多少
		$User = M('news'); // 实例化User对象
		$count      = $User->where()->count();// 查询满足要求的总记录数
		$Page       = new \Think\AjaxPage($count,$num);// 实例化分页类 传入总记录数和每页显示的记录数
		$list = $User->where()->order('id')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($list as $key=>$value){
		$row[] = array(
			'id' => $value['id'],
			'content' => $value['title']
			);
		}
		$show       = $Page->show();// 分页显示输出
		$this->ajaxReturn(array('1'=>$row,'2'=>$show),JSON);
	}
	public function ajax_get(){  //用来显示ajax分页
		$this->display();
	}
	public function soso(){
		//$title = I('name');
		//$titles = I('sunyang','你好');
		//echo $title.$titles;
		$this->display();
	}
	public function ajax_soso(){
		$title = trim(I('title',null));
		$data['title'] = array('like','%'.$title.'%');
		$num = 12 ;//要求分页显示多少
		$User = M('news'); // 实例化User对象
		$count      = $User->where($data)->count();// 查询满足要求的总记录数
		$Page       = new \Think\AjaxPage($count,$num);// 实例化分页类 传入总记录数和每页显示的记录数
		$list = $User->where($data)->order('id')->limit($Page->firstRow.','.$Page->listRows)->select();
		if($title!=''){ //当输入关键词不为空
			foreach($list as $key=>$value){
			$row[] = array(
				'id' => $value['id'],
				'title' => preg_replace("/$title/","<b style='color:red;'>".$title."</b>",$value['title'])
				);
			}
		}else{  //当输入关键词为空时
			foreach($list as $key=>$value){
			$row[] = array(
				'id' => $value['id'],
				'title' =>$value['title']
				);
			}
		}
		$show       = $Page->show();// 分页显示输出
		$this->ajaxReturn(array('1'=>$row,'2'=>$show),JSON);
	}
	public function admin(){
		$this->display();
	}
	public function upload(){  //上传七牛照片
		$setting=C('UPLOAD_SITEIMG_QINIU');
		$Upload = new \Think\Upload($setting);
		$info = $Upload->upload($_FILES);
		dump($info);
	}
}